﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

/// <summary>
///     元数据带标签元素的样式配置。
/// </summary>
/// <remarks>
///     <code>
/// Style ( Color = "Blue", ElementAlign = Right, Hidden = False )
/// Style ( Cell ( BorderColor = "Blue", BorderStyle = Double ) )
/// Style ( Cell = Double )
/// Style ( Control ( Accelerator = "R", Type = ListBox ) )
/// </code>
/// </remarks>
public class MetadataStyle : MetadataListWithAreal<MetadataStyleProperty>
{
    private readonly SyntaxToken _declareKeywordToken;

    internal MetadataStyle(SyntaxNode? parent, SyntaxToken declareKeywordToken) :
        base(SyntaxKinds.MetadataStyles, parent)
    {
        SetChildField(ref _declareKeywordToken, declareKeywordToken);
    }


    public SyntaxToken DeclareKeywordToken => _declareKeywordToken;


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken);
        base.AcceptVisitor(visitor);
    }
}


public static partial class NodeFactory
{
    public static MetadataStyle CreateMetadataStyle(SyntaxNode? parent, Identifier? arealName,
        SyntaxToken declareKeywordToken, IEnumerable<MetadataStyleProperty>? properties)
    {
        Debug.Assert(declareKeywordToken.IsOneOfNode(SyntaxKinds.StyleKeywordToken,
            SyntaxKinds.LabelStyleKeywordToken));

        MetadataStyle style = new(parent, declareKeywordToken);

        if (!Identifier.IsDefaultOrEmpty(arealName))
        {
            style.Update(arealName);
        }

        return InitializeMetadataListWithAreal(style, properties);
    }
}